$(function(){
	var walletType=sessionStorage.getItem("walletType");
	var logonToken=sessionStorage.getItem("logonToken");
	var playId=sessionStorage.getItem("playId");
	var json = {
        "logonToken": logonToken,
        "walletType": walletType,
        "playId":playId
    }
    $.ajax({
        type: "post",
        url: url + '/bigWinner/api/donation/donationPage',
        data: JSON.stringify(json),
        dataType: 'json',
        contentType: "application/json",
        success: function(result) {
            if (result.success) {
//				活动列表
				var activityList = result.obj.allActivity;
				var activityList_html='<option value="">请选择你要参与的活动</option>';
				for(var i in activityList){
					activityList_html += '<option value="'+activityList[i].id+'">'+activityList[i].activityName+'</option>';
				}
				$(".sel_hd").html(activityList_html);
				
				//	最新活动
				var record = result.obj.allActivity;
				if(record == "" || record == null || record == undefined){
					$(".sel_row").css("opacity","0");
					$(".cutBtn").find("img").css("display","none");
				}else{
					record = result.obj.allActivity;
					if($(".sel_hd option").length > 0){
						$(".sel_hd option").eq(1).attr("selected","selected");
					}
					$(".activityName").html(record[0].activityName);
					$(".nowNum").html("第"+record[0].nowNum+"轮");
					$(".nowTargetAmount").html(record[0].nowTargetAmount);
					$(".nowRaisedAmount").html(record[0].nowRaisedAmount);
					if(isNaN(record[0].nowRaisedAmount/record[0].nowTargetAmount)){
						
					}else{
						$(".progress .active").css("width",(record[0].nowRaisedAmount/record[0].nowTargetAmount)*100+"%").html((record[0].nowRaisedAmount/record[0].nowTargetAmount)*100+"%");
					}
					if(record[0].nowStatus == "0"){
						$(".nowStatus").html("进行中");
					}else{
						$(".nowStatus").html("已结束");
					}
				}
               
            } else {
                isErr(result);
                $(".sel_row").css("opacity","0");
				$(".cutBtn").find("img").css("display","none");
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("请求失败："+XMLHttpRequest.status);
        }
    });
    
//  切换活动
	$(".sel_hd").on("change",function(){
		var type=$(".sel_hd option:selected").val();
		var json = {
	        "logonToken": logonToken,
	        "walletType": walletType,
	        "playId":playId,
	        "activityId":type
	    }
	    $.ajax({
	        type: "post",
	        url: url + '/bigWinner/api/donation/select',
	        data: JSON.stringify(json),
	        dataType: 'json',
	        contentType: "application/json",
	        success: function(result) {
	            if (result.success) {
	            	var data=result.obj.activityRecord;
	              	$(".activityName").html(data.activityName);
					$(".nowNum").html("第"+data.nowNum+"轮");
					$(".nowTargetAmount").html(data.nowTargetAmount);
					$(".nowRaisedAmount").html(data.nowRaisedAmount);
					if(isNaN(data.nowRaisedAmount/data.nowTargetAmount)){
						
					}else{
						$(".progress .active").css("width",(data.nowRaisedAmount/data.nowTargetAmount)*100+"%").html((data.nowRaisedAmount/data.nowTargetAmount)*100+"%");
					}
					
					if(data.nowStatus == "0"){
						$(".nowStatus").html("进行中");
					}else{
						$(".nowStatus").html("已结束");
					}
					$(".sel_row").css("opacity","1");
	            } else {
	                isErr(result);
	                $(".sel_row").css("opacity","0");
					$(".cutBtn").find("img").css("display","none");
	            }
	        },
	        error: function(XMLHttpRequest, textStatus, errorThrown) {
	            alert("请求失败："+XMLHttpRequest.status);
	        }
	    });
	})
    
})
